package com.uphone.kingmall.activity.personal;

import androidx.fragment.app.Fragment;

import com.blankj.utilcode.util.LogUtils;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;
import com.uphone.kingmall.base.BaseTabActivity;
import com.uphone.kingmall.fragment.MyTeamFragment;
import com.uphone.kingmall.listener.onNormalRequestListener;
import com.uphone.kingmall.utils.MyUrl;
import com.uphone.kingmall.utils.OkGoUtils;
import com.uphone.kingmall.utils.SharedPreferencesHelper;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * <pre>
 *     author : 王雨
 *     e-mail :
 *     time   : 2018/07/31
 *     desc   :
 *     version: 1.0
 * </pre>
 */
public class MyTeamActivity extends BaseTabActivity {

    private int secondCount;
    private int firstCount;

    @Override
    protected String initTitle() {
        return "我的团队";
    }

    @Override
    public void initView() {
        super.initView();
        isLoad = false;
        HttpParams params = new HttpParams();
        params.put("userId", SharedPreferencesHelper.getUserId());
        OkGoUtils.normalRequest(MyUrl.userGroupNum, params, new onNormalRequestListener() {
            @Override
            public void onSuccess(String body, int code) {
                try {
                    JSONObject jsonObject = new JSONObject(body);
                    JSONObject map = jsonObject.getJSONObject("map");
                    secondCount = map.getInt("userGroupererji");
                    firstCount = map.getInt("userGroupyiji");
                } catch (JSONException e) {
                    LogUtils.e("异常：" + e.toString());
                    e.printStackTrace();
                } finally {
                    trackIndicator.setVisibleNum(2);
                    isLoad = true;
                    initData();

                }
            }

            @Override
            public void onError(Response<String> response) {

            }
        });
    }

    @Override
    protected List<Fragment> getFragmentList() {
        ArrayList<Fragment> list = new ArrayList<>();
        list.add(MyTeamFragment.newInstance(1));
        list.add(MyTeamFragment.newInstance(2));
        return list;
    }

    @Override
    protected void selectChange(boolean selected) {

    }

    @Override
    protected String[] getItems() {
        String[] tabs = {"一级团队(" + firstCount + ")", "二级团队(" + secondCount + ")"};
        return tabs;
    }
}